<?php
declare(strict_types=1);
namespace app\admin\controller;
use app\facade\Basic;
use app\admin\service\Seller as ServiceSeller;
use think\Request;

/**
 *  供应商/零售商
 */
class Seller extends BaseController
{

    /**
     *   获取枚举
     */
    public function resource(Request $request)
    {
        $param['field'] = $request->param('field');
        $serviceSeller = new ServiceSeller();
        $result = $serviceSeller->getEnum($param);
        return Basic::json($result);
    }

    /**
     *  供应商/零售商
     */
    public function getList(Request $request)
    {
        $param['pageIndex'] = $request->param('pageIndex',1);
        $param['pageSize'] = $request->param('pageSize',50);
        $param['category'] = $request->param('category',null);
        $param['name'] = $request->param('name',null);
        $param['sup_type'] = $request->param('sup_type',null);
        $param['phone'] = $request->param('phone',null);
        $param['email'] = $request->param('email',null);
        $param['name']  = trim($param['name']);
        /* 验证 */
        $this->validateData($param,'Seller.getList');

        $serviceRetrieve = new ServiceSeller();
        $result = $serviceRetrieve->getList($param);
        return Basic::json($result);
    }


    /**
     *  添加机型
    */
    public function save(Request $request)
    {
        $param['creator'] = $request->operator_id;
        $param['name'] = $request->param('name',null);
        $param['domain'] = $request->param('domain',null);
        $param['category'] = $request->param('category',null);
        $param['sup_type'] = $request->param('sup_type',null);
        $param['phone'] = $request->param('phone',null);
        $param['email'] = $request->param('email',null);
        $param['qq'] = $request->param('qq',null);
        $param['wechat'] = $request->param('wechat',null);
        $param['whatsapp'] = $request->param('whatsapp',null);
        $param['dingtalk'] = $request->param('dingtalk',null);
        $param['country'] = $request->param('country',null);
        $param['is_deal'] = $request->param('is_deal',null);
        $param['address'] = $request->param('address',null);
        $param['tags'] = $request->param('tags',null);
        $param['owner'] = $request->param('owner',null);
        $param['partner'] = $request->param('partner',null);
        $param['att_path'] = $request->param('att_path',null);
        $param['contact'] = $request->param('contact',null);
        $param['remark'] = $request->param('remark',null);
        $param['name']  = trim($param['name']);
        /* 验证 */
        $this->validateData($param,'Seller.save');

        $serviceSeller = new ServiceSeller();
        $result = $serviceSeller->save($param);
        return Basic::json($result);
    }


    /**
     *  获取详情
    */
    public function detail(Request $request)
    {
        $param['operator_id'] = $request->operator_id;
        $param['id'] = $request->param('id',null);
        /* 验证 */
        $this->validateData($param,'Seller.detail');

        $serviceRetrieve = new ServiceSeller();
        $result = $serviceRetrieve->detail($param);
        return Basic::json($result);
    }

    /**
     *  修改机型
    */
    public function update(Request $request)
    {
        $param['updater'] = $request->operator_id;
        $param['id'] = $request->param('id',null);
        $param['name'] = $request->param('name',null);
        $param['domain'] = $request->param('domain',null);
        $param['category'] = $request->param('category',null);
        $param['sup_type'] = $request->param('sup_type',null);
        $param['phone'] = $request->param('phone',null);
        $param['email'] = $request->param('email',null);
        $param['qq'] = $request->param('qq',null);
        $param['wechat'] = $request->param('wechat',null);
        $param['whatsapp'] = $request->param('whatsapp',null);
        $param['dingtalk'] = $request->param('dingtalk',null);
        $param['country'] = $request->param('country',null);
        $param['is_deal'] = $request->param('is_deal',null);
        $param['address'] = $request->param('address',null);
        $param['tags'] = $request->param('tags',null);
        $param['owner'] = $request->param('owner',null);
        $param['partner'] = $request->param('partner',null);
        $param['att_path'] = $request->param('att_path',null);
        $param['contact'] = $request->param('contact',null);
        $param['remark'] = $request->param('remark',null);
        $param['name']  = trim($param['name']);
        /* 验证 */
       $this->validateData($param,'Seller.update');

        $serviceRetrieve = new ServiceSeller();
        $result = $serviceRetrieve->update($param);
        return Basic::json($result);
   }

    /**
     *  删除机型
    */
    public function delete(Request $request)
    {
        $param['updater'] = $request->operator_id;
        $param['ids'] = $request->param('ids',null);

        /* 验证 */
        $this->validateData($param,'Seller.delete');

        $serviceRetrieve = new ServiceSeller();
        $result = $serviceRetrieve->delete($param);
        return Basic::json($result);
    }



}
